{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "9cfcbc26-2f73-4893-b4ad-70153466678c",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2024-10-14T15:43:53.563630Z",
     "iopub.status.busy": "2024-10-14T15:43:53.562997Z",
     "iopub.status.idle": "2024-10-14T15:43:53.572555Z",
     "shell.execute_reply": "2024-10-14T15:43:53.570259Z",
     "shell.execute_reply.started": "2024-10-14T15:43:53.563584Z"
    }
   },
   "outputs": [],
   "source": [
    "from IPython.display import Image"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "2fb2db2b-effd-46fe-8c53-22f7cca1795c",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2024-10-14T15:43:54.968278Z",
     "iopub.status.busy": "2024-10-14T15:43:54.967636Z",
     "iopub.status.idle": "2024-10-14T15:43:54.980845Z",
     "shell.execute_reply": "2024-10-14T15:43:54.978750Z",
     "shell.execute_reply.started": "2024-10-14T15:43:54.968222Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<img src=\"./imgs/gnn_layers.png\" width=\"500\"/>"
      ],
      "text/plain": [
       "<IPython.core.display.Image object>"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "Image(url='./imgs/gnn_layers.png', width=500)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "8a01bc67-10d2-42c7-ab15-5566f383cd1b",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2024-10-14T15:45:04.557978Z",
     "iopub.status.busy": "2024-10-14T15:45:04.557351Z",
     "iopub.status.idle": "2024-10-14T15:45:08.682441Z",
     "shell.execute_reply": "2024-10-14T15:45:08.680521Z",
     "shell.execute_reply.started": "2024-10-14T15:45:04.557932Z"
    }
   },
   "outputs": [],
   "source": [
    "import torch_geometric as pyg"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "b7bea46c-52cc-4f6a-87f8-39a6de5de259",
   "metadata": {},
   "source": [
    "- 2708 nodes, 10556 edges\n",
    "- Each node describes a document.\n",
    "- Each node is described by a FEATURE TENSOR.\n",
    "    -  x_1, ..., x_1433\n",
    "-  Two documents are connected (with an edge) if there exists a citation link in CORA between them."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "6bdca450-8147-4843-b17c-6634da63be66",
   "metadata": {},
   "source": [
    "### InMemoryDataset"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "fb731a18-4ddb-4149-87dd-ddd02ba3d028",
   "metadata": {},
   "source": [
    "- Dataset base class for creating graph datasets which easily fit into CPU memory."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "dae55b20-1c01-4143-a4bb-28f7075d1427",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2024-10-19T03:03:50.870103Z",
     "iopub.status.busy": "2024-10-19T03:03:50.869429Z",
     "iopub.status.idle": "2024-10-19T03:03:50.878801Z",
     "shell.execute_reply": "2024-10-19T03:03:50.876627Z",
     "shell.execute_reply.started": "2024-10-19T03:03:50.870053Z"
    }
   },
   "outputs": [],
   "source": [
    "# !pip install rdkit"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "621ffa4e-9029-4131-b37f-2e09d164b9d1",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2024-10-19T03:05:12.239026Z",
     "iopub.status.busy": "2024-10-19T03:05:12.238693Z",
     "iopub.status.idle": "2024-10-19T03:05:12.246822Z",
     "shell.execute_reply": "2024-10-19T03:05:12.244862Z",
     "shell.execute_reply.started": "2024-10-19T03:05:12.239004Z"
    }
   },
   "outputs": [],
   "source": [
    "from torch_geometric.datasets import QM9"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "d6bf3868-d4ca-45b8-9679-347de10160f9",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2024-10-19T03:08:34.780446Z",
     "iopub.status.busy": "2024-10-19T03:08:34.779792Z",
     "iopub.status.idle": "2024-10-19T03:10:15.343084Z",
     "shell.execute_reply": "2024-10-19T03:10:15.342250Z",
     "shell.execute_reply.started": "2024-10-19T03:08:34.780397Z"
    }
   },
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "Processing...\n",
      "100%|██████████| 133885/133885 [01:34<00:00, 1413.15it/s]\n",
      "Done!\n"
     ]
    }
   ],
   "source": [
    "dp = QM9(root='./data/QM9/').to_datapipe()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "id": "3bc0d371-c824-40c3-9621-dabc6996fb0b",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2024-10-19T03:12:37.817601Z",
     "iopub.status.busy": "2024-10-19T03:12:37.817102Z",
     "iopub.status.idle": "2024-10-19T03:12:37.828669Z",
     "shell.execute_reply": "2024-10-19T03:12:37.826502Z",
     "shell.execute_reply.started": "2024-10-19T03:12:37.817566Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Batcher"
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "dp = dp.batch_graphs(batch_size=16, drop_last=True)\n",
    "dp"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "id": "6825ac76-675f-4a77-8ead-3c03243b5f15",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2024-10-19T03:12:39.340635Z",
     "iopub.status.busy": "2024-10-19T03:12:39.340037Z",
     "iopub.status.idle": "2024-10-19T03:12:40.342465Z",
     "shell.execute_reply": "2024-10-19T03:12:40.340739Z",
     "shell.execute_reply.started": "2024-10-19T03:12:39.340590Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "DataBatch(x=[12622, 11], edge_index=[2, 24802], edge_attr=[24802, 4], y=[1024, 19], pos=[12622, 3], z=[12622], smiles=[16], name=[16], idx=[1024], batch=[12622])"
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "batch = next(iter(dp))\n",
    "batch"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.13"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
